/**
 * Created by chenyong on 2015/3/21.
 */

$(document).ready(function () {
    $(".autoclear").click(function () {
        if ($(this).attr('value') == $(this).attr('default')) {
            $(this).attr('value', '');
        }
    });
    $(".autoclear").focus(function () {
        if ($(this).attr('value') == $(this).attr('default')) {
            $(this).attr('value', '');
        }
    });
    $(".autorefill").blur(function () {
        if ($(this).attr('value') == '') {
            $(this).attr('value', $(this).attr('default'));
        }
    });
    $(".autoselectall").click(function () {
        $(this).select();
    });
});
jQuery.fn.log = function (msg) {
    return this;
};
$.urlParam = function (url, name) {
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(url);
    return results[1] || 0;
}
function dump(arr, level) {
    var dumped_text = "";
    if (!level) level = 0;
    var level_padding = "";
    for (var j = 0; j < level + 1; j++) level_padding += "    ";
    if (typeof(arr) == 'object') {
        for (var item in arr) {
            var value = arr[item];
            if (typeof(value) == 'object') {
                dumped_text += level_padding + "'" + item + "' ...\n";
                dumped_text += dump(value, level + 1);
            } else {
                dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
            }
        }
    } else {
        dumped_text = "===>" + arr + "<===(" + typeof(arr) + ")";
    }
    return dumped_text;
}
function is_set(item) {
    if (item != undefined) return true;
    return false;
}
function is_empty(string) {
    if (string != undefined && string == '') {
        return true;
    } else {
        return false;
    }
}
function is_email(string) {
    var pattern = /^([a-zA-Z0-9'_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if (string != undefined && pattern.test(string)) {
        return true;
    } else {
        return false;
    }
}
function is_texthaschanged(element) {
    texthaschanged = false;
    if (pano().get(element + '.placeholder') != pano().get(element + '.text')) {
        texthaschanged = true;
    }
    return texthaschanged;
}
function clean_string(string) {
    var pattern = /[\-,?~!@#$%&*+\-'="]/g
    return string.replace(pattern, "");
}
function xml_log(network_y, action_y, target_y) {
    log("social", {
        network: network_y,
        action: action_y,
        target: target_y
    });
}